package com.ronan.imserver.service.impl;

import com.ronan.common.pojo.RimUmsInfo;
import com.ronan.common.utils.SessionManager;
import com.ronan.imserver.rpc.RpcWebService;
import com.ronan.imserver.service.RIMService;
import io.netty.channel.Channel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


/**
 * FileName    : com.ronan.imserver.service.impl
 * Description :
 *
 * @author : ronan
 * @version : 1.0
 * Create Date : 2021/2/26 17:27
 **/
@Service
public class RIMServiceImpl implements RIMService {

    @Autowired
    private RpcWebService rpcWebService;


    /**
     * 用户离线
     *
     * @param ums     用户
     * @param channel 通道
     */
    @Override
    public void userOffline(RimUmsInfo ums, Channel channel) {

        if (null != ums) {
            // step1.清理本地的信息
            SessionManager.removeSession(ums.getAccid());

            // step2.清楚redis登录状态
            clearLoginStatus(ums);
        }
        SessionManager.remove(channel);
    }

    /**
     * 清除登录状态
     *
     * @param ums 用户
     */
    @Override
    public void clearLoginStatus(RimUmsInfo ums) {
        rpcWebService.offline(ums);
    }
}
